<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    //1、新增的API
    // /**
    //  * Object 拓展的新方法，如：
    //  * keys(obj):获取对象的所有key形成的数组
    //  * values(obj):获取对象的所有value形成的数组
    //  * entries(obj):获取对象的所有key和value形成的二维数组。
    //  * assign(dest,...src):将多个src对象的值拷贝到dest中。（第一层深拷贝，第二层浅拷贝）
    //  * /
    const person = {
        name:"jack",
        age:21,
        language:['java','js','css']
    };
    console.log(Object.keys(person));//["name","age","lanuage"]
    console.log(Object.values(person));
    console.log(Object.entries(person));

    const target = {a:1};
    const sources1 = {b:2};
    const sources2 = {c:3};

    Object.assign(target,sources1,sources2)
    console.log(target)

    //2、声明对象简写
    const age = 23;
    const name = "张三";
    //传统
    const person1 = {age:age,name:name};
    console.log(person1);
    //ES6：属性名和属性值变量名，可以省略
    const person2 = {age,name}
    console.log(person2)

    //3、对象的函数属性简写
    let person3 = {
        name:"jack",
        //以前:
        eat:function(food){
            console.log(this.name + "在吃" + food);
        },
        //箭头函数:这里拿不到this
        eat2:food => console.log(person3.name+"在吃"+food),
        //简写版:
        eat3(food){
            console.log(this.name+"在吃"+food)
        }
    }
    person3.eat("apple")

    //4、对象拓展运算符（...）用于取出参数对象所有可遍历属性然后拷贝到当前对象
    //1）、拷贝对象（深拷贝）
    //let person4 = {name:"Amy",age:15}
    //let someone = {...person4}
    //console.log(someone)

    //2）、合并对象
    let age = {age: 15}
    let name = {name: "Amy"}
    let person5 = { ...age, ...name }
    console.log(person5)
</script>
<body>
    
</body>
</html>